<?php

$name=$_REQUEST["userName"];
$pwd=$_REQUEST["pwd"];
$img=$_FILES["file"];


if(!empty($name) && !empty($pwd) && !empty($img)){
    $imgpath="upload/".$img["name"];
    if($img["error"]==0){
        $isok=move_uploaded_file($img["tmp_name"],$imgpath);
        if(!$isok){
            exit("图片上传失败");
        }
    }
    $pdo=new PDO("mysql:dbname=caipin;host=127.0.0.1;charset=UTF8","root","root");


    $sql= $pdo->prepare("insert into useraa(name,pwd,img) values(:name,:pwd,:img);");
    $sql->execute(array("name"=>$name,"pwd"=>$pwd,"img"=>$imgpath));

    $sql2=$pdo->prepare("select * from useraa;");
    $sql2->execute();
    $arr=$sql2->fetchAll(PDO::FETCH_NAMED);
    foreach($arr as $k=>$v){

        echo "<li>下标：".$k." 用户：".$v["name"]."<img src=\"".$v["img"]."\"/></li>";
    }

}



?>

<form method="post" enctype="multipart/form-data">
    用户名：<input name="userName"/>
    密码：<input name="pwd"/>

    头像：<input type="file" name="file"/>
    <button>添加</button>
</form>